from django.http.response import HttpResponseNotFound
try:
    from django.utils.deprecation import MiddlewareMixin  # Django 1.10.x
except ImportError:
    MiddlewareMixin = object  # Django 1.4.x - Django 1.9.x
from django.http import HttpResponseRedirect
class SimpleMiddleware(MiddlewareMixin):
    def process_request(self, request):
        http_user_agent = request.META.get('HTTP_USER_AGENT')
        # remote_addr = request.META.get('REMOTE_ADDR')
        http_user_agent = str(http_user_agent).lower()
        print(request.path)
        if request.session.get('userId') is None:
            if request.path!="/login/":
                if "admin" in request.path or "logout" in request.path:
                    return None
                return   HttpResponseRedirect('/login/')
            else:
                return None
        return None

    def process_response(self, request, response):
        return response